package com.dyz.leetcode;

public class DiameterOfBinaryTree543 {
    private int max = 0;
    public int diameterOfBinaryTree(TreeNode root) {
        if(root==null){return 0;}
        depath(root);
        return max;
    }
    private int depath(TreeNode root){
        if(root==null){
            return 0;
        }
        int L = depath(root.left);
        int R = depath(root.right);
        max = Math.max(max, L+R);

        return Math.max(L, R)+1;
    }
}
